package com.dreamana.ui
{
	import com.dreamana.command.BaseCommand;
	
	import flash.display.BitmapData;
	
	public class SkinRemoveCommand extends BaseCommand
	{
		private var _component:ISkinnable;
		private var _dispose:Boolean;
		
		public function SkinRemoveCommand(component:ISkinnable, dispose:Boolean=true)
		{
			_component = component;
			_dispose = dispose;
		}
		
		override public function execute():void
		{
			if(_component) {
				var map:Object = _component.getStyleMap();
				for(var style:String in map)
				{
					var obj:Object = map[style];
					
					if(obj is BitmapData) {
						var data:BitmapData = obj as BitmapData;
						
						//recover default skin
						_component.setStyle(style, null);
						
						//dispose bitmapdata
						if(_dispose) data.dispose();
						
						//clear reference?
						delete map[style];
					}
				}
			}
			
			//finish!
			this.complete();
		}
	}
}